package org.clockworkmages.games.anno1186.situations.combat.options;

import org.clockworkmages.games.anno1186.GameBeansContext;
import org.clockworkmages.games.anno1186.GameDataService;
import org.clockworkmages.games.anno1186.model.character.IncapacitatedState;
import org.clockworkmages.games.anno1186.model.character.Stat;
import org.clockworkmages.games.anno1186.model.option.Option;
import org.clockworkmages.games.anno1186.scripting.PlayerCharacterScriptingWrapper;
import org.clockworkmages.games.anno1186.situations.combat.CombatSituation;

public class ResistIncapacitatedStateOption
		extends Option {

	// @Injected
	// private GameStateService gameStateService;
	// @@Injected
	// private PlayerCharacterScriptingWrapper playerCharacterScriptingWrapper;

	// private IncapacitatedState incapacitatedState;
	// private int difficulty;
	private boolean success;
	private CombatSituation combatSituation;

	public ResistIncapacitatedStateOption(
			IncapacitatedState incapacitatedState, int difficulty,
			CombatSituation combatSituation) {
		// this.incapacitatedState=incapacitatedState;
		// GameStateService gameStateService;
		this.combatSituation = combatSituation;
		GameDataService gameDataService = GameBeansContext
				.getBean(GameDataService.class);
		PlayerCharacterScriptingWrapper playerCharacterScriptingWrapper = GameBeansContext
				.getBean(PlayerCharacterScriptingWrapper.class);
		;
		int chance = playerCharacterScriptingWrapper.statChance(
				incapacitatedState.getResistingStatId(), difficulty);

		Stat stat = gameDataService.getGameData().getStats()
				.get(incapacitatedState.getResistingStatId());
		setLabel(incapacitatedState.getResistingOptionLabel() + "("
				+ stat.getName() + ", " + chance + "%)");

		this.success = playerCharacterScriptingWrapper.statRoll(
				incapacitatedState.getResistingStatId(), difficulty);
		setTextAfter(this.success ? incapacitatedState
				.getResistingSuccessText() : incapacitatedState
				.getResistingFailureText());
		setConsumesCombatAction(true);
	}

	@Override
	public void select() {
		if (success) {
			combatSituation.setIncapacitatedState(null);
		}
		super.select();
	}

}
